'use strict';

const Controller = require('egg').Controller;

class HomeController extends Controller {
  async index() {
    const {
      ctx,
    } = this;
    ctx.body = 'hi, egg';
  }
  async data() {
    this.ctx.body = {
      data: ['123', 45611789],
    };
  }
  async postData() {
    this.ctx.body = {
      data: [123, 789],
      msg: ' 收到 ',
    }
  }
  async getBook() {
    // console.log(this.ctx.query);
    const api = 'https://app.zhuanzhuan.com/zzopen/sellbook/pcHomePageList?pageNum=' + this.ctx.query.num + '&pageSize=20&cateId2=100&cateId3=100';
    const response = await this.ctx.curl(api);

    const data = JSON.parse(response.data);
    this.ctx.body = data;
  }
  async getLunbo() {
    // data = JSON.stringify
    // console.log(this.service.shuju.lunboData());

    this.ctx.body = await this.service.shuju.lunboData();
  }
  async getGoodItem() {
    const that = this.ctx.query;
    // console.log(that);

    const response = await this.ctx.curl('https://zhuan.58.com/zzopen/sellbook/bookDetail?infoId=' + that.infoId);
    // const response = await this.ctx.curl('https://zhuan.58.com/zzopen/sellbook/bookDetail?infoId=972048157834330123')
    // console.log(response.data);
    this.ctx.body = response.data;
  }
  async getMoreDetail() {
    const bookId = this.ctx.query.bookId;
    const response = await this.ctx.curl('https://zhuan.58.com/zzopen/sellbook/moreBookDetail?bookId=' + bookId);
    // console.log(response);
    this.ctx.body = response.data;


  }
}

module.exports = HomeController;